package com.kingsalert.kingsalert.view.process_widget;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.kingsalert.kingsalert.R;
import com.kingsalert.kingsalert.base.BaseProcessWidgetManager;
import com.kingsalert.kingsalert.bean.process.ProcessInfo_Data;
import com.kingsalert.kingsalert.util.http.HttpUtil;


public class GenderSelectViewManager extends BaseProcessWidgetManager {

    private TextView titleTv;
    private TextView maleTv, femaleTv;

    private boolean isMale = true;

    public GenderSelectViewManager(View view, ProcessInfo_Data data,String pageTag){
        super(view,data,pageTag);
    }

    @Override
    protected void init(){

        titleTv = mView.findViewById(R.id.vpgs_tv_title);
        maleTv = mView.findViewById(R.id.vpgs_tv_male);
        femaleTv = mView.findViewById(R.id.vpgs_tv_female);

        maleTv.setOnClickListener(v -> setGender(true));
        femaleTv.setOnClickListener(v -> setGender(false));

        setTitle(mData.getTitle());

    }

    @Override
    public boolean checkInput() {
        return true;
    }

    @Override
    public String getInput() {
        return isMale ? "MALE":"FEMALE";
    }

    public void setGender(boolean isMale){
        this.isMale = isMale;
        if (isMale){
            maleTv.setBackgroundResource(R.drawable.bg_green_ll_rc24dp_border_green_1dp);
            maleTv.setTextColor(mView.getContext().getColor(R.color.green_main));
            femaleTv.setBackgroundResource(R.drawable.bg_gray_rc24dp);
            femaleTv.setTextColor(Color.parseColor("#FF6E6E6E"));
        }else {
            maleTv.setBackgroundResource(R.drawable.bg_gray_rc24dp);
            maleTv.setTextColor(Color.parseColor("#FF6E6E6E"));
            femaleTv.setBackgroundResource(R.drawable.bg_green_ll_rc24dp_border_green_1dp);
            femaleTv.setTextColor(mView.getContext().getColor(R.color.green_main));
        }

        HttpUtil.getInstance().saveBuriedPoint(page,mData.getParamName().toUpperCase()+"_CLICK",getInput());
    }

    public void setTitle(String title){
        if (TextUtils.isEmpty(title)) titleTv.setVisibility(GONE);
        else {
            titleTv.setVisibility(VISIBLE);
            titleTv.setText(title);
        }
    }

}
